package com.lsa.skienna.challenge.chap1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class LCD {
	
	private static final String lineFeed = "\n";

	public static void main(String[] args) throws Throwable {
		Digits digits = new Digits();
		
		digits.addDigit('1', new Command[] {Command.WHITESPACE, Command.MULTI_WHITESPACE, Command.VCHAR_AND_DOWN, Command.LOCAL_CR, Command.WHITESPACE, Command.MULTI_WHITESPACE,
				Command.VCHAR_AND_DOWN }
		);
		
		digits.addDigit('2', new Command[] { Command.WHITESPACE, Command.HCHAR,
				Command.VCHAR_AND_DOWN, Command.LOCAL_CR, 
				Command.WHITESPACE, Command.HCHAR, Command.LOCAL_CR, 
				Command.VCHAR_AND_DOWN, Command.WHITESPACE, Command.HCHAR
				 }
		);
		
		digits.addDigit('3', new Command[] {Command.WHITESPACE, Command.HCHAR, Command.VCHAR_AND_DOWN, Command.LOCAL_CR,
				Command.WHITESPACE, Command.HCHAR, Command.VCHAR_AND_DOWN, Command.LOCAL_CR, Command.WHITESPACE, Command.HCHAR}
		);
		
		digits.addDigit('4', new Command[] { Command.CURSOR_DOWN, Command.VWALLS, Command.WHITESPACE,
				Command.HCHAR, Command.VCHAR_AND_DOWN
				 }
		);
		
		digits.addDigit('5', new Command[] {Command.WHITESPACE, Command.HCHAR, Command.LOCAL_CR,
				Command.VCHAR_AND_DOWN, Command.WHITESPACE, Command.HCHAR, Command.VCHAR_AND_DOWN, Command.LOCAL_CR,
				Command.WHITESPACE, Command.HCHAR, 
				 }
		);
		
		digits.addDigit('6', new Command[] {Command.WHITESPACE, Command.HCHAR, Command.LOCAL_CR,
				Command.VCHAR_AND_DOWN, Command.WHITESPACE, Command.HCHAR, Command.LOCAL_LF, Command.VWALLS,
				Command.WHITESPACE, Command.HCHAR, 
				 }
		);
		
		digits.addDigit('7', new Command[] {Command.WHITESPACE, Command.HCHAR, Command.VCHAR_AND_DOWN, Command.VCHAR_AND_DOWN});
		
		digits.addDigit('8', new Command[] {Command.WHITESPACE, Command.HCHAR, Command.LOCAL_LF, Command.VWALLS,
				Command.WHITESPACE, Command.HCHAR, Command.LOCAL_LF, Command.VWALLS,
				Command.WHITESPACE, Command.HCHAR,
				});
		
		digits.addDigit('9', new Command[] {Command.WHITESPACE, Command.HCHAR, Command.LOCAL_LF, Command.VWALLS,
				Command.WHITESPACE, Command.HCHAR, Command.VCHAR_AND_DOWN, Command.LOCAL_CR,
				Command.WHITESPACE, Command.HCHAR,
				});
		
		digits.addDigit('0', new Command[] {Command.WHITESPACE, Command.HCHAR, Command.LOCAL_LF, Command.VWALLS,
				Command.CURSOR_DOWN, Command.VWALLS,
				Command.WHITESPACE, Command.HCHAR,
				});
		
		TaskReader taskReader = new TaskReader(System.in);
		Task task = null;
		
		Canvas c = new Canvas();
		while( (task = taskReader.readNextTask()) != null) {
			c.reset(task.s, task.chars.length());
			for (int i = 0; i < task.chars.length(); i++) {
				digits.getDigit(task.chars.charAt(i)).render(c);
				c.nextDigit();
			}
			c.printTo(System.out);
		}
		
	}
	
	static class Digits {
		private Map<Character, Digit> sourceChar2Digit = new HashMap<Character, Digit>();
		
		public void addDigit(char sourceChar, Command[] commands) {
			sourceChar2Digit.put(sourceChar, new Digit(sourceChar, commands){});
		}
		
		public Digit getDigit(char sourceChar) {
			return sourceChar2Digit.get(sourceChar);
		}
	}
	
	static abstract class Digit {
		private Command[] commands;
		protected char sourceChar;

		protected Digit(char sourceChar, Command[] commands) {
			this.commands = commands;
			this.sourceChar = sourceChar;
		}
		
		public char getSourceChar() {
			return sourceChar;
		}

		public void render(Canvas canvas) {
			for (Command c : commands) {
				switch(c) {
				case WHITESPACE:
					canvas.drawChar(' ');
					break;
				case MULTI_WHITESPACE:
					canvas.drawMultiChar(' ');
					break;
				case HCHAR:
					canvas.drawMultiChar('-');
					break;
				case CURSOR_DOWN:
					canvas.cursorDown();
					break;
				case VCHAR_AND_DOWN:
					canvas.drawChar(' ');
					canvas.backSpace();
					canvas.cursorDown();
					canvas.drawMultiCharVertically('|');
					break;
				case VWALLS:
					canvas.drawVWall('|');
					break;
				case LOCAL_CR:
					canvas.localCarriageReturn();
					break;
				case LOCAL_LF:
					canvas.cursorDown();
					canvas.localCarriageReturn();
					break;
				}
			}
		}
	}
	
	static class Canvas {
		
		private char[][] canvasData;
		private int cursorX;
		private int cursorY;
		
		private int s;
		private int currentDigit;
		
		public void reset(int s, int digitCount) {
			canvasData = new char[ 2*s + 3 ][ (s + 3)*digitCount - 1 ];
			for (int i = 0; i < canvasData.length; i++) {
				char[] row = canvasData[i];
				for (int j = 0; j < row.length; j++) {
					row[j] = ' ';
				}
				
			}
			cursorX = 0;
			cursorY = 0;
			this.s = s;
			currentDigit = 0;
		}
		
		public void drawMultiChar(char c) {
			for (int i = 0; i < s; i++) {
				drawChar(c);
			}
		}
		
		public void localCarriageReturn() {
			cursorY = (s + 3)*currentDigit;
		}
		
		public void drawMultiCharVertically(char c){
			for (int i = 0; i < s; i++) {
				canvasData[cursorX++][cursorY] = c;
			}
		}
		
		public void drawVWall(char c) {
			for (int i = 0; i < s; i++) {
				canvasData[cursorX][cursorY] = c;
				canvasData[cursorX][cursorY + s + 1] = c;
				cursorX++;
			}
		}
		
		public void drawChar(char c) {
			canvasData[cursorX][cursorY++] = c;
		}
		
		public void backSpace() {
			cursorY--;
		}
		
		public void cursorDown() {
			cursorX++;
		}
		
		public void lineFeed() {
			cursorX = 0;
			cursorY++;
		}
		
		public void nextDigit() {
			currentDigit++;
			cursorX = 0;
			cursorY = (s + 3)*currentDigit;
		}
		
		public void printTo(PrintStream stream) {
			for (char[] row : canvasData) {
				for (int i = 0; i < row.length; i++) {
					stream.print(row[i]);
				}
				stream.print(lineFeed);
			}
			stream.print(lineFeed);
			stream.flush();
		}
	}
	
	static class TaskReader{
		private BufferedReader reader;
		
		TaskReader(InputStream stream) {
			this.reader = new BufferedReader(new InputStreamReader(stream));
		}
		
		Task readNextTask() throws IOException{
			Task task = null;
			
			String line = reader.readLine();
			if (line == null){
				return null;
			}
			
			Scanner scanner = new Scanner(line);
			try{
				task = new Task();
				
				task.s = scanner.nextInt();
				task.chars = scanner.next(); 
				
				if (task.s == 0) return null;
			}
			catch(RuntimeException e){
				return null;
			}
			
			
			return task;
		}
	}
	
	static class Task{
		int s;
		String chars;
	}
	
	enum Command{
		WHITESPACE,
		MULTI_WHITESPACE,
		HCHAR,
		CURSOR_DOWN,
		VCHAR_AND_DOWN,
		VWALLS,
		LOCAL_CR,
		LOCAL_LF
	}
}
